// 标题插件：统一设置浏览器标题
// 对外规范 URL 由 Nginx rewrite 映射到 /pages/pc/*

const PREFIX = '养老系统-';
const DEFAULT_NAME = '养老系统';

const map = {
  '/pages/pc/login': '登录',
  '/pages/pc/index': '首页',
  '/pages/pc/register': '注册',
  '/pages/pc/passwordForgot': '忘记密码',
  '/pages/pc/passwordReset': '修改密码',
  '/pages/pc/personalInfo': '个人信息填写',
  '/pages/pc/remind': '提醒',
  '/pages/pc/remindEdit': '提醒编辑',
  '/pages/pc/aiChat': 'AI通话'
};

function norm(p){
  if(!p) return ''; if(p.length>1 && p.endsWith('/')) return p.slice(0,-1); return p;
}

export function applyTitle(pathname){
  try {
    const path = norm(pathname || location.pathname);
    const name = map[path];
    document.title = name ? (PREFIX + name) : DEFAULT_NAME;
  } catch(e){}
}

export default {
  install(app){
    applyTitle();
    window.addEventListener('popstate', ()=> applyTitle());
    app.config.globalProperties.$setPageTitle = applyTitle;
  }
};
